package net.portly.cst;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import net.portly.cst.flex.FlexAssetAttribute;

public class StructuralAssetInstance implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private AssetIdType idType;
	private String id;
	private String type;
	private String name;
	private String createdby;
	private String createddate;
	private String description;
	private String publist;
	private String status;
	private String updatedby;
	private String updateddate;
	private String fw_uid;
	private List<FlexAssetAttribute> flexAssetAttributes;
	private String assettypename;

	public StructuralAssetInstance(Map<String, String> metaMap, List<FlexAssetAttribute> flexAssetAttributes) {
		// * TODO - introspection !!!
		id = metaMap.get("id");
		type = metaMap.get("type");
		name = metaMap.get("name");
		createdby = metaMap.get("createdby");

		createddate = metaMap.get("createddate");
		description = metaMap.get("description");
		publist = metaMap.get("publist");
		status = metaMap.get("status");
		updatedby = metaMap.get("updatedby");
		updateddate = metaMap.get("updateddate");
		fw_uid = metaMap.get("fw_uid");
		
		this.flexAssetAttributes = flexAssetAttributes;
		
		if (flexAssetAttributes != null) {
			Collections.sort(this.flexAssetAttributes);
		}
		
		idType = new AssetIdType(id);
		idType.setFw_uid(fw_uid);
	}

	public String toString() {
		return "id: " + idType.getId() + " name: " + name + getTypeString() + " createdby: " + createdby + " createddate: " + createddate + attrsToString();
	}

	public String getTypeString() {
		return type != null && assettypename != null ? " type: " +  type + ( assettypename.length() > 0 ? " ( " + assettypename + " ) " : "") : "";
	}

	public String attrsToString() {
		StringBuffer ret = new StringBuffer("");
			
		if (flexAssetAttributes != null) {
			ret.append("\n   attributes [\n");
			
			for (FlexAssetAttribute attr : flexAssetAttributes) {
				ret.append("\t" + attr.toString() + "\n");
			}
			ret.append("   ]\n");
		}
		
		return ret.toString();
	}
	
	public String getId() {
		return idType.getId();
	}

	public String getType() {
		return type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCreatedby() {
		return createdby;
	}

	public void setCreatedby(String createdby) {
		this.createdby = createdby;
	}

	public String getCreateddate() {
		return createddate;
	}

	public void setCreateddate(String createddate) {
		this.createddate = createddate;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getPublist() {
		return publist;
	}

	public void setPublist(String publist) {
		this.publist = publist;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getUpdatedby() {
		return updatedby;
	}

	public void setUpdatedby(String updatedby) {
		this.updatedby = updatedby;
	}

	public String getUpdateddate() {
		return updateddate;
	}

	public void setUpdateddate(String updateddate) {
		this.updateddate = updateddate;
	}

	public String getFw_uid() {
		return fw_uid;
	}

	public void setFw_uid(String fw_uid) {
		this.fw_uid = fw_uid;
	}

	public List<FlexAssetAttribute> getFlexAssetAttributes() {
		return flexAssetAttributes;
	}
}
